package com.hc.log4j2;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.CountDownLatch;

/**
 * @author : cdhuangchao3
 * @Date : 2018/10/26 16:40
 * @Description :
 */
@Slf4j
public class Log4j2Test {

    private static Integer totalThread = 50;

    public static void main(String[] args) throws InterruptedException {
        // 开50个线程，打印一段固定长度的日志，100万行，95M左右
//        fixedPrinting(100*10000);
        // 开50个线程，打印大量的日志，1000万行，1G左右
        fixedPrinting(1000 * 10000);
    }

    private static void fixedPrinting(int all) throws InterruptedException {
        System.out.println("log4j2 "+(all/10000)+"万 start fixedPrinting");
        final CountDownLatch cdl = new CountDownLatch(totalThread);
        long startTime = System.currentTimeMillis();
        final int count = all / totalThread;
        for (int i=0; i<totalThread; i++) {
            new Thread(new Runnable() {
                public void run() {
                    for (int j=0; j<count; j++) {
                        log.info("Hello World fixedPrinting");
                    }
                    cdl.countDown();
                }
            }).start();
        }
        cdl.await();
        long endTime = System.currentTimeMillis();
        System.out.println("log4j2 "+(all/10000)+"万："+(endTime - startTime)+"ms");
    }

}
